<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:c="livcos.org/ns/cosmos"
  xmlns:job="livcos.org/ns/process/job"
  xmlns:u="livcos.org/ns/cosmos/update"
  xmlns="http://www.w3.org/1999/xhtml"
  exclude-result-prefixes="c job u">
  
  <xsl:import href="../../style/base.xsl"/>
  
  <xsl:output method="html"/>
  
  <xsl:param name="login"/>
  <xsl:param name="pw"/>
  
  <xsl:variable name="msg"/>
  
  <xsl:template match="/">
    <html>
      <head>
        <title>LivCos Login</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <style type="text/css">
          body {
            background-color: #FAFAFF;
            font-family: Verdana;
          }
          table {
            text-align: right;
            margin: 200px auto;
          }
        </style>
        <script type="text/javascript">
          <xsl:variable name="session" select="doc(*/*[2]/@session)"/>
          <xsl:comment>
            function encVal(inp) {
              var b = '<xsl:value-of select="$session/*[@name = 'enc-base']"/>';
              var v = inp.value;
              var c = "";
              var hex = "0123456789ABCDEF";
              for (var i = 0; i &lt; v.length; ++i) {
                var t = v.charCodeAt(i) + b.charCodeAt(i);
                if (t > 255)
                  alert(t);
                c += hex.charAt(t / 16) + hex.charAt(t % 16);
              }
              inp.value = b.substring(16) + c;
            }
          </xsl:comment>
        </script>
      </head>
      <body onload="if (top != window) top.location = window.location; document.getElementById('login').focus();">
        <form method="GET" action="login" onsubmit="encVal(this.pw)">
          <table>
            <xsl:if test="normalize-space($msg) != ''">
              <tr>
                <td colspan="2" style="color: red;"><xsl:value-of select="$msg"/></td>
              </tr>
            </xsl:if>
            <tr>
              <td><label for="login">Login:</label></td>
              <td><input type="text" name="login" id="login" value="{$login}"/></td>
            </tr>
            <tr>
              <td><label for="pw">Password:</label></td>
              <td><input type="password" name="pw" id="pw" value="{$pw}"/></td>
            </tr>
            <tr>
              <td colspan="2">
                <input type="submit" value="Login"/>
              </td>
            </tr>
          </table>
        </form>
      </body>
    </html>
  </xsl:template>
  
</xsl:stylesheet>
